<template>
  <div class="control-item">
    <div class="control-header">
      <span class="control-name">公告</span>
      <span @click="showBeautyBox = true">组件美化</span>
    </div>
    <div class="control-body">
      <div class="control-section">
        <!-- 模板样式 -->
        <div class="control-item">
          <div class="control-title">模板样式</div>
          <div class="control-content">
            <div class="example-list">
              <div
                class="example-item"
                v-for="(item, index) in exampleList"
                @click="setStyleType(item)"
                :class="styleType == item.value ? 'active' : ''"
                :key="index"
              >
                <i class="iconfont" :class="item.icon"></i>
              </div>
            </div>
          </div>
        </div>
        <!-- 图片设置 -->
        <uploadImg
          v-if="styleType == 3"
          :uploadImg="params.params.noticeImg"
          size="不限*40px"
          @uploadSuccess="uploadSuccess"
          @deleteImg="deleteImg"
        ></uploadImg>
        <!-- 公告内容 -->
        <div class="control-item justify-section">
          <div class="control-title flex-between">
            <span>公告内容</span>
            <span class="reset" @click="resetItem">重置</span>
          </div>
          <div class="control-content">
            <div class="noticeText">
              <a-textarea
                v-model="params.params.noticeText"
                placeholder="请输入公告内容"
                :rows="4"
              />
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 组件美化 -->
    <comBeautyBox
      :showBeautyBox="showBeautyBox"
      @handleBack="showBeautyBox = false"
    >
      <div>
        <!-- 背景配置 -->
        <bgControl :backgroudData="params.moduleCss"></bgControl>
        <!-- 间距控制组件 -->
        <spaceControl
          :spaceData.sync="params.moduleCss"
          @resetSpace="resetSpace"
          @resetMp="resetMp"
        ></spaceControl>
      </div>
    </comBeautyBox>
  </div>
</template>

<script>
import bgControl from "@/components/DiyNew/diy/baseControl/bgControl/index.vue";
import uploadImg from "@/components/DiyNew/uploadImg/index.vue";

import comBeautyBox from "@/components/DiyNew/diy/comBeautyBox/comBeautyBox.vue";
import spaceControl from "@/components/DiyNew/diy/baseControl/spaceControl/index.vue";

export default {
  name: "diyNoticeControl",
  components: {
    bgControl,
    uploadImg,
    comBeautyBox,
    spaceControl,
  },
  props: {
    params: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      showBeautyBox: false,
      exampleList: [
        {
          icon: "icon-tupian",
          type: "模板1",
          value: "1",
        },
        {
          icon: "icon-tubiao",
          type: "模板2",
          value: "2",
        },
        {
          icon: "icon-zidingyi",
          type: "模板3",
          value: "3",
        },
      ],
    };
  },
  watch: {},
  computed: {
    styleType: {
      get() {
        return this.params.params.styleType || "1";
      },
    },
  },
  methods: {
    // 设置样式
    setStyleType(item) {
      this.$setWithAction(this.params, "styleType", item.value);
    },
    // 上传图片成功回调
    uploadSuccess(e) {
      this.$setWithAction(this.params, "noticeImg", e.val);
    },
    // 删除图片回调
    deleteImg(e) {
      this.$setWithAction(this.params, "noticeImg", "");
    },
    resetItem() {
      this.$set(this.params.params, "noticeText", "");
    },
    // 重置圆角
    resetSpace(e) {
      let type = e.type;
      console.log(type);
      this.$set(this.params.moduleCss, type, 0);
    },
    // 重置边距
    resetMp() {
      this.$set(this.params.moduleCss, "margin", 0);
      this.$set(this.params.moduleCss, "padding", 0);
    },
  },
};
</script>

<style lang="scss" scoped>
.control-item {
  width: 100%;
  height: 100%;
  margin: 0 auto;
  .control-header {
    width: 100%;
    height: 48px;
    background: #ffffff;
    border-bottom: 1px solid #f0f2f5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px 14px 24px;
    span {
      font-size: 12px;
      color: #8c8c8c;
    }
    .control-name {
      font-size: 14px;
      font-weight: 600;
      color: #000000;
    }
    span:nth-child(2) {
      cursor: pointer;
    }
  }
  .control-body {
    width: 100%;
    .control-section {
      width: 228px;
      margin: 0 auto;
      text-align: center;
      .control-item {
        width: 100%;
        .control-title {
          padding: 24px 0 14px 0;
          font-size: 12px;
          color: #000000;
          text-align: left;
        }
        .control-content {
          .example-list {
            width: 100%;
            display: flex;
            flex-wrap: wrap;
            .example-item {
              width: 70px;
              height: 70px;
              background: #f6f7f9;
              border-radius: 4px;
              margin-right: 8px;
              display: flex;
              justify-content: center;
              align-items: center;
              cursor: pointer;
              overflow: hidden;
              .iconfont {
                font-size: 60px;
              }

              span {
                color: #9da3ac;
                font-size: 12px;
              }
            }
            .example-item:last-child {
              margin-right: 0;
            }
            .active {
              border: 2px solid #1890fc;
            }
          }
        }
      }

      .justify-section {
        .flex-between {
          display: flex;
          justify-content: space-between;
          .reset {
            font-size: 12px;
            color: #9e9e9e;
            cursor: pointer;
          }
        }
        .control-content {
          width: 100%;
          height: 40px;
          background: #f6f7f9;
          border-radius: 4px;
          .noticeText {
            ::v-deep .ant-input {
              width: 100%;
              background: #ffffff;
              background: #f6f7f9;
              border: 0 none;
              border-radius: 4px;
              resize: none;
            }
          }
        }
      }
    }
  }
}
</style>
